<?php 
	// No direct access
	defined('_JEXEC') or die;
?>

<script type="text/javascript">
	$('#s1').cycle({
	    fx:     'scrollHorz',
	    speed:  'fast',
	    prev:   '#prev1',
	    next:   '#next1',
	    timeout: 0
	});
</script>
<div>
	<div class="appMainImage">
		<?php //include_once 'includes/ads/ads_200x200.php';?>
		<?php include_once 'includes/categories/categories.php';?>
		<?php 
			$modules =& JModuleHelper::getModules('left_top');
			foreach ($modules as $module){
			   echo JModuleHelper::renderModule($module);
			}
		?>
	</div>
	<div class="appReview">
		<h1 class="entry-title"><strong><?php echo $this->item->main_title; ?></strong></h1>
			<?php if($this->user->id == 50 || $this->user->id == 42): ?>
<!-- 			<div style="background-color: #ECECEC; border: solid 1px #CCCCCC; padding: 5px; color:#000000"> -->
<!-- 				Add Download Link: -->
<!-- 				<table> -->
<!-- 					<tr> -->
<!-- 						<td>Link:</td> -->
<!-- 						<td><input style="width: 400px;" id="add_link" type="text" name="link" value=""> -->
<!-- 						<td><a id="add_link_btn">Add</a></td> -->
<!-- 					</tr> -->
<!-- 				 </table> -->
			<script>
				jQuery.noConflict();
				jQuery(document).ready(function(){
			       	jQuery('#add_link_btn').click(function(){
				       	jQuery('#add_link_btn').hide();
						jQuery.ajax({
						  type: 'POST',
						  url: '<?php echo JURI::base();?>index2.php?option=com_apkipas&task=addLink',
						  data: 'link='+urlencode(jQuery('#add_link').val())+'&itemid='+<?php echo $this->item->title_id; ?>+'&itune_id='+<?php echo $this->item->itune_id; ?>,
						  success: function(data){
						  		if(data == 1){
									alert('add link success ');
									jQuery('#add_link').val('');
						  		}
								else
									alert('add link error. Try again ');
						  		jQuery('#add_link_btn').show();
							}
						});
					});
					
					function urlencode (str) {
		    			str = (str + '').toString();
		    			return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
					}
		
			     });
			</script>
<!-- 		  </div> -->
<!-- 		  <br> -->
		<?php endif; ?>
		<div class="appBodyText">
			<?php echo utf8_decode($this->item->des); ?>
		</div>
	</div>
	<div class="appInfo">
		<img width="160px" src="<?php echo $this->item->bg; ?>" >
		<?php if($this->item->ipad_iphone == 1): ?>
			<p><img style="margin-bottom: -2px;" src="templates/apkipas/images/universal.png"><span>This app is designed for both iPhone and iPad.</span></p>
			<br>
		<?php endif; ?>
		<p>Category: <?php echo $this->item->category; ?></p>
		<p>Updated: <?php echo $this->item->updated; ?></p>
		<p>Version: <?php echo $this->item->version; ?></p>
		<p>Size: <?php echo $this->item->size; ?></p>
		<p>Language: <?php echo $this->item->language; ?></p>
		<p>Seller: <?php echo $this->item->seller; ?></p>
		<p>Requirements: <?php echo $this->item->requirements; ?></p>
	</div>
	<a class="iTunesLink" target="_blank" href="http://itunes.apple.com/app/id<?php echo $this->item->itune_id; ?>?mt=8">
		<img alt="Available on the iTunes App Store" src="templates/apkipas/images/icon_appstore.png">
	</a>
	
	<br style="clear: both;">
	<div>
		<div class="appMainImage">
			<?php include_once 'includes/ads/ads_160x600.php';?>
		</div> 
		<div class="appReview appScreenshots">
			<h3>Screenshots</h3>
			<div id="s1" class="pics" style="position: relative; overflow: hidden;">
				<?php if($this->item->p1 != ''): ?>
					<img src="<?php echo $this->item->p1; ?>" alt="download <?php echo $this->item->title; ?>" title="download <?php echo $this->item->title; ?>">
				<?php endif; ?>
				<?php if($this->item->p2 != ''): ?>
					<img src="<?php echo $this->item->p2; ?>" alt="<?php echo $this->item->title; ?> ipa" title="<?php echo $this->item->title; ?> ipa">
				<?php endif; ?>
				<?php if($this->item->p3 != ''): ?>
					<img src="<?php echo $this->item->p3; ?>" alt="<?php echo $this->item->title; ?>" title="<?php echo $this->item->title; ?>">
				<?php endif; ?>
				<?php if($this->item->p4 != ''): ?>
					<img src="<?php echo $this->item->p4; ?>" alt="<?php echo $this->item->main_title; ?>" title="<?php echo $this->item->main_title; ?>">
				<?php endif; ?>
				<?php if($this->item->p5 != ''): ?>
					<img src="<?php echo $this->item->p5; ?>" alt="download <?php echo $this->item->title; ?> ipa" title="download <?php echo $this->item->title; ?> ipa">
				<?php endif; ?>
			</div>
			<div id="nav" style="text-align:center; padding-top: 10px;">
				<a id="prev1" class="buttonclick" href="javascript:void(null);"></a>
				<a id="next1" class="buttonclick" href="javascript:void(null);"></a>
			</div>
			<div class="tags">
				<?php foreach ($this->tags as $tag): ?>
					<?php if($tag->alias != ''):?>
						<span class="tag"><a href="<?php echo JRoute::_('index.php?option=com_apkipas&view=detail&layout=tag&tag='.$tag->alias)?>"><?php echo $tag->text; ?></a></span>
					<?php endif;?>
				<?php endforeach; ?>
			</div>
		</div>
		<div class="appInfo">
		    <p>Some links we searched from other websites for you to test before making purchase:</p>
		    <br>
			<?php if(count($this->download) >= 1 ): foreach ($this->download as $row): ?>
				<?php if(count($row->link) > 0): ?>
					<div class="appname">VERSION <?php echo $row->version; ?></div>
					<ul class="linkbox">
						<?php foreach ($row->link as $link):?>
							<li class="link_detail"><a target="_blank" href="<?php echo $link->link?>"><?php echo $link->source ?></a></li>
						<?php endforeach; ?>
						<li style="padding-bottom:10px;" ></li>
					</ul>
				<?php endif;?>
			<?php endforeach; endif;?>
		</div>
	</div>
</div>
<br style="clear: both;">
	<?php if(count($this->category_related) > 0):?>
	<ul class="appPrevious">
		<h3>More Apps or Games on the same category</h3>
		<?php foreach ($this->category_related as $item):?>
			<li>
				<a href="<?php echo JRoute::_('index.php?option=com_apkipas&view=detail&id='.$item->title_id.':'.$item->alias.'&Itemid=107'); ?>">
					<img src="<?php echo $item->bg; ?>" height="88" width="88">
				</a>
				<h4><?php echo $item->main_title; ?></h4>
				<p><?php echo ApkipasHelper::wordLimit($item->des,20); ?></p>
				<a href="<?php echo JRoute::_('index.php?option=com_apkipas&view=detail&id='.$item->title_id.':'.$item->alias.'&Itemid=107'); ?>">Read more...</a>
			</li>
		<?php endforeach;?>
	</ul>
	<?php endif;?>
	<?php if(count($this->seller_related) > 0):?>
	<ul class="appPrevious">
		<h3>More Apps or Games from Seller</h3>
		<?php foreach ($this->seller_related as $item):?>
			<li>
				<a href="<?php echo JRoute::_('index.php?option=com_apkipas&view=detail&id='.$item->title_id.':'.$item->alias.'&Itemid=107'); ?>">
					<img src="<?php echo $item->bg; ?>" height="88" width="88">
				</a>
				<h4><?php echo $item->main_title; ?></h4>
				<p><?php echo ApkipasHelper::wordLimit($item->des,20); ?></p>
				<a href="<?php echo JRoute::_('index.php?option=com_apkipas&view=detail&id='.$item->title_id.':'.$item->alias.'&Itemid=107'); ?>">Read more...</a>
			</li>
		<?php endforeach;?>
	</ul>
	<?php endif;?>
	<?php if(count($this->tag_related) > 0):?>
	<ul class="appPrevious">
		<h3>More Apps or Games by tags</h3>
		<?php foreach ($this->tag_related as $item):?>
			<li>
				<a href="<?php echo JRoute::_('index.php?option=com_apkipas&view=detail&id='.$item->title_id.':'.$item->alias.'&Itemid=107'); ?>">
					<img src="<?php echo $item->bg; ?>" height="88" width="88">
				</a>
				<h4><?php echo $item->main_title; ?></h4>
				<p><?php echo ApkipasHelper::wordLimit($item->des,20); ?></p>
				<a href="<?php echo JRoute::_('index.php?option=com_apkipas&view=detail&id='.$item->title_id.':'.$item->alias.'&Itemid=107'); ?>">Read more...</a>
			</li>
		<?php endforeach;?>
	</ul>
	<?php endif;?>